package com.chakid.mobileplay2.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

import com.chakid.mobileplay2.R;


public class SplashActivity extends Activity {

    private static final String TAG=SplashActivity.class.getSimpleName();
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //两秒后执行到这里
                startMainActivity();
                Log.e(TAG,"当前线程名=="+Thread.currentThread().getName());
            }
        },3000);
    }

    private boolean isStartMain = false;

    /**
     * 跳转到主页面，并把当前页面关闭
     */
    private void startMainActivity() {
        if(!isStartMain) {
            isStartMain = true;
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            //关闭当前页面
            finish();
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        startMainActivity();
        Log.e(TAG,"onTouchEvent==Action"+event.getAction());
        return super.onTouchEvent(event);
    }

    @Override
    protected void onDestroy() {

        //移除所有的消息和任务，防止多次点击启动页面的时候，进入多个MainActivity
        handler.removeCallbacksAndMessages(null);
        super.onDestroy();
    }
}
